Completed
Push — master ( 4fcad4...efcce7 )
by Muhammad Dyas
19s queued 16s
created

response.ts ➔ buildActionResponse   A

Complexity

Conditions 1

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 18
c 0
b 0
f 0
rs 9.95
cc 1
1
import {chat_v1 as chatV1} from 'googleapis/build/src/apis/chat/v1';
2
3
/**
4
 * Creates an action response.
5
 * Action Response is parameter that a Chat app can use to configure how its
6
 * response is posted.
7
 * ref: https://developers.google.com/chat/api/reference/rest/v1/spaces.messages#actionresponse
8
 *
9
 * @param {string} message - Number of votes for this option
10
 * @param {string} status - Status of
11
 * @returns {object} - ActionResponse
12
 */
13
export function createStatusActionResponse(message: string, status = 'OK') {
14
  return {
15
    actionResponse: {
16
      type: 'DIALOG',
17
      dialogAction: {
18
        actionStatus: {
19
          statusCode: status,
20
          userFacingMessage: message,
21
        },
22
      },
23
    },
24
  };
25
}
26
27
/**
28
 * Creates an action response with specific type
29
 * ref: https://developers.google.com/chat/api/reference/rest/v1/spaces.messages#responsetype
30
 * @param {object} message - Card message either text or cardsV2
31
 * @returns {object} - ActionResponse
32
 */
33
export function createDialogActionResponse(message: object) {
34
  const responseBody: chatV1.Schema$Message = {
35
    actionResponse: {
36
      type: 'DIALOG',
37
      dialogAction: {
38
        dialog: {
39
          body: message,
40
        },
41
      },
42
    },
43
  };
44
  return responseBody;
45
}
46